<?php

$section->appendSystemModule('right_sidebar', array('name'=>'events.eventInterested'));
// append map on sidebar
$section->appendSystemModule('right_sidebar', array('name'=>'cms.html','params' => array('html_content' => $this->element("event_view_map",array('showStreetView'=>true)))));
?>

<?php 
uses("Flay");
$html->css('/events/css/events.css',null,array(),false);
?>
<div class="noborder">
	<div class="events view">
		<div class="fl event_content" style="width: 60%;">
					<div class="row">
					<strong><?php echo __('Category');?></strong>
					<div class="value">
						<?php echo $html->link($event['EventCategory']['name'], array('plugin'=>'events', 'controller' => 'events', 'action' => 'index', 'categoryId'=>$event['EventCategory']['id'], 'eventDate'=>null)); ?>
					</div>
				</div>
									<div class="row">

					<strong><?php echo __('When');?></strong>
										<div class="value">

						<?php
						$eventWhen = date("l, F, d h:i a",strtotime($event['Event']['event_from']));
						if(isset($event['Event']['event_to']) && $event['Event']['event_to']!=null)
						{
							$eventWhen = $eventWhen . ' - <BR/>' . date("l, F, d h:i a",strtotime($event['Event']['event_to']));
						}
						echo $eventWhen;
						
						$tmpStartDate = date("Ymd\THis\Z",strtotime($event['Event']['event_from']));
						$tmpEndDate = date("Ymd\THis\Z",strtotime($event['Event']['event_to']));
						$addToCalDate = $tmpStartDate . "/" . $tmpEndDate;
						
						$partialDescription = strip_tags($event['Event']['description']);
						$partialDescription = str_replace(array("\n"), "", $partialDescription);
						$flayTextLimit = cr("EventConfig.flay_text");
						if($flayTextLimit && strlen($partialDescription) > $flayTextLimit)
						{
							$partialDescription = Flay::fragment($partialDescription,$flayTextLimit);
						}
						echo "<br/>";
						echo "<a href=\"http://www.google.com/calendar/event?action=TEMPLATE&text=".$event['Event']['title']."&dates=".$addToCalDate."&details=".$partialDescription."&location=".$event['Event']['venue']."&trp=false&sprop=".$html->url($event['Event']['viewUrl'], true)."\" target=\"_blank\">".__("Add to Google Calendar")."</a>";
						echo "<br/>";
						
						echo $html->link(__('Add to Outlook Calendar', true), array("plugin"=>"events",'controller'=>'events','action'=>'generate_cal_file',$event['Event']['id']));
						?>
					</div>
				
								</div>
									<div class="row">

					<strong><?php echo __('Venue'); ?></strong>
										<div class="value">

						<?php echo $event['Event']['venue']; ?>
					</div>
												</div>

													<div class="row">

					<strong><?php echo __('Cost'); ?></strong>
										<div class="value">

						<?php
						if(isset($event['Event']['event_cost']) && $event['Event']['event_cost']>0) 
						{
							echo "$ ".$event['Event']['event_cost'];
							if (isset($event['Event']['event_cost_to']) && $event['Event']['event_cost_to']>0)
							{
								echo " ".__("to")." $ ".$event['Event']['event_cost_to'];
							}
						} else {
							echo __("Free");
						}
						?>
					</div>
																	</div>

																			<?php 
			if ($event['Event']['event_site']!="" || $event['Event']['ticket_site']!="")
			{
			?>
																<div class="row">

				<strong><?php echo __('How');?></strong>
									<div class="value">

					<?php 
					if ($event['Event']['event_site'] !=="") 
					{
						if(substr($event['Event']['event_site'], 0,7) === "http://" || substr($event['Event']['event_site'], 0,6) === "https:") { 
							$url = $event['Event']['event_site'];  
						} else { 
							$url = "http://".$event['Event']['event_site'];
						}
						echo $html->link($event['Event']['event_site'],$url, array('target' => '_blank'));
						echo "<br/>";
					}
					if ($event['Event']['ticket_site'] !=="") 
					{
						if(substr($event['Event']['ticket_site'], 0, 7) === "http://" || substr($event['Event']['ticket_site'], 0, 6) === "https:") {
							$url = $event['Event']['ticket_site'];
						} else {
							$url = "http://".$event['Event']['ticket_site'];
						}
						echo $html->link($event['Event']['ticket_site'],$url, array('target' => '_blank'));
					}
					?></div>
																					</div>

			
			<?php
			}
			?>

						<?php if(isset($event['Event']['listing_id']) && !is_null($event['Event']['listing_id']) && $event['Event']['listing_id']) {?>
			<div class="row">

				<strong><?php echo __('Business'); ?></strong>
													<div class="value">

					<?php echo $html->link($listing['Listing']['title'],$html->url($listing['Listing']['viewUrl'], true)); ?>
					
					<div>
					<?php 
					$_userReviewCount = '<div style="float:left;margin-left:80px">('.$listing['Listing']['review_count'].')</div>';
					$_userRating = $listing['Listing']['userAvg'];
					echo $rating->display(array('rating'=>$_userRating,'before_text'=>$_userReviewCount,'tooltip'=>__('User Rating').' '.number_format($_userRating,1),'tooltipClass'=>'user_'.$listing['Listing']['id'].'_'.mt_rand(1,1000)));
					if(cr('GeneralConfig.disable_editor_reviews') != 1)
					{
						$_editorRating = $listing['Listing']['editorialAvg'];
						echo $rating->display(array('rating'=>$_editorRating,'class'=>'editor_rating_star_value', 'parent_class'=>'editor_rating_star_base', 'tooltip'=>__('Editor Rating').' '.number_format($_editorRating,1),'tooltipClass'=>'editor_'.$listing['Listing']['id'].'_'.mt_rand(1,1000)));
					}
					?>
				</div>
					</div>
				</div>
			
			<?php } ?>
<div class="row">
	<strong><?php echo __('Submitted By');?></strong>
									<div class="value">

					<?php
					if(isset($event['Event']['user_id']) && isset($event['User']))
					{
						echo $html->link($html->image($event['User']['avatar'],array('class'=>"profile_pic",'alt'=>sprintf(__("%s profile"),$event['User']['username']),'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$event['User']['profile_url'],array("escape"=>false));
						echo "&nbsp;&nbsp;&nbsp;".$html->link($event['User']['display_name'], $event['User']['profile_url']);
					}
					else
					{
						echo __("Admin");
					}
					?>
				</div>
				</div>

				
		</div>
		<div class="fl images_section">
			<?php
			$img = $html->image($event['Event']['image'],array('thumb'=>array('crop'=>true,'width'=>200,'height'=>150),'class'=>'thumbnail','alt'=>sprintf(__("%s picture"),$event['Event']['title'])));
			echo $html->link($img, array('plugin'=>'events',"controller"=>"event_assets",'action'=>'index','event','eventId'=>$event['Event']['id']),array('escape'=>false));
			?>
			<br />
			<!-- code to show event assets starts here-->
			<?php if(!empty($eventAssets))
			{?>
				<ul>
				<?php
				$imageLimit = 3;
				$i = 0;
				foreach($eventAssets as $eventAsset)
				{
					$eventAsset = $eventAsset['EventAsset'];
					if($i == $imageLimit)
					{
						break;
					}
					?>
					<li style='float: left;'>
					<?php echo $html->link($html->image($eventAsset['file_url'],array('thumb'=>array('crop'=>true,'width'=>60,'height'=>45))),array('plugin'=>'events',"controller"=>"event_assets",'action'=>'index','event','eventId'=>$event['Event']['id'],'show'=>$eventAsset['id']),array('escape'=>false));?>
					</li>
					<?php $i++;
				}?>
				</ul>
			<?php }?>
			<div class="clear"></div>
			<?php
			$allowImageLinks = true;
			?>
			<?php if($allowImageLinks && $loggedInUser){?>
			<?php echo $html->link(__('Upload pic'),array('plugin'=>'events','controller'=>'event_assets','action'=>'add',$event['Event']['id']),array('class'=>'fr'));?>
			<br />
			<?php } ?>
			<?php if(count($eventAssets)){?>
			<?php echo $html->link(__('View All Pics'),array('plugin'=>'events',"controller"=>"event_assets",'action'=>'index','event','eventId'=>$event['Event']['id']),array('class'=>'fr'))?>
			<?php } ?>
			<div class="clear"></div>
			<!-- code to show event assets ends here-->

				<?php if ($loggedInUser) { ?>
		<div class="actions">
			<?php 
				echo "<h4>".__("Are You Interested ?")."</h4><br/>";
				if($isLoggedInUserAttending==0 && $isLoggedInUserInterested==0) 
				{
					echo $html->link(__("I'm in", true), array('controller'=>'events','action'=>'add_attendee',$event['Event']['id']),array('class'=>'button button_small'));
					echo $html->link(__("Sounds Cool", true), array('plugin'=>'events','controller'=>'events','action'=>'add_soundscool',$event['Event']['id']),array('class'=>'button button_small'));
				} else {
					if($isLoggedInUserAttending) 
					{
						echo __("You Replied").": <strong>".__("I'm in!")."</strong> ";
						echo $html->link(__("Cancel", true), array('plugin'=>'events','controller'=>'events','action'=>'revoke_attendee',$event['Event']['id']));
					}
					if($isLoggedInUserInterested) 
					{
						echo __("You Replied").": <strong>".__("Sounds Cool!")."</strong> ";
						echo $html->link(__("Cancel", true), array('plugin'=>'events','controller'=>'events','action'=>'revoke_soundscool',$event['Event']['id']));
					}
				}
				echo "		<div class='clear'></div>
";
				/*
				echo "<br/>";
				if(!$isSubscriber)
				{
					echo $html->link(__('Subscribe', true), array('plugin'=>'events','controller'=>'events','action'=>'add_subscriber',$event['Event']['id']),array('class'=>'button'));
				}
				else
				{
					echo $html->link(__('Unsubscribe', true), array('plugin'=>'events','controller'=>'events','action'=>'remove_subscriber',$event['Event']['id']),array('class'=>'button'));
				}
				*/
			?>
		</div>
	<?php } ?>

		</div>
		<div class="clear"></div>
		
	
			
				
			
			<?php if ($event['Event']['description'] != ""){ ?>
			<hr>
				<strong><?php echo __('What/Why'); ?></strong><br/>
				
					<?php echo $event['Event']['description']; ?>


					<?php if((isset($showEditLink) || isset($showDeleteLink)) && ($showEditLink==true || $showDeleteLink==true)){ ?>
				
					
							
								<center>
								<?php 
									if(isset($showEditLink) && ($showEditLink==true)){
										echo "";
										echo "<div class='fr'>".$html->link(__('Edit', true), array("plugin"=>"events",'controller'=>'events','action'=>'edit',$event['Event']['slug']))."</div>";
										echo "";
									}
								?>
								</center>
								<center>
								<?php 
									if(isset($showDeleteLink) && ($showDeleteLink==true)){
										echo "<div class='fr'>|</div>";
										echo "<div class='fr'>".$html->link(__('Delete', true), array("plugin"=>"events",'controller'=>'events','action'=>'delete',$event['Event']['id']),null,sprintf(__('Are you sure you want to delete # %s?', true), $event['Event']['title']))."</div>";
										echo "";
									}
								?>
								</center>		
							<hr>

			
			<?php } ?>
	
	
			<!--
			<?php
			if(!empty($event['Event']['popularized_date'])) {
			?>
				
					<strong><?php echo __('Popularized On');?></strong>:
					
						<?php echo $event['Event']['popularized_date']; ?>
					
				
			<?php } ?>
		
	
		
			
				
					<strong><?php echo __('Comments Received');?></strong>: 
					<?php echo $event['Event']['comment_count']; ?>
				
				
					<strong><?php echo __('Total Views');?></strong>: 
					<?php echo $event['Event']['views_count']; ?>
				
				
				
					<strong><?php echo __('Attendees');?></strong>: 
					<?php echo $event['Event']['whosin_count']; ?>
				
				
					<strong><?php echo __('Considered Cool By');?></strong>: 
					<?php echo $event['Event']['soundscool_count']; ?>
				
				-->

	<div class="clear"></div>
			
								
							
					
					
				
			<?php } ?>
	
	</div>


	<div id="event_comments" class="related">
		<h3><?php echo __('Discuss This Event');?></h3>
		<?php
		if(!empty($comments))
		{
			echo "";
			foreach ($comments as $comment)
			{
				echo "<div class='comment_box altrow '>";
				echo "<div class='post_info fl'>";
				if(isset($comment['User']))
				{
					echo $html->link($html->image($comment['User']['avatar'],array('class'=>"profile_pic",'alt'=>sprintf(__("%s profile"),$comment['User']['display_name']),'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$comment['User']['profile_url'],array("escape"=>false));
					echo " ";
					echo $html->link($comment['User']['display_name'],$comment['User']['profile_url']).__(" ");					
				}
				else
				{
					//echo __("Admin");
				}
				echo " ";
				echo "</div><div class='comment_body fl'>";
				echo "<div class='time'>";	
				echo $time->timeAgoInWords($comment['EventComment']['created'],array('shortString'=>true));
				echo "</div>";	
 				echo "<div class='clear'></div>";
				echo $comment['EventComment']['description']."<br/>";
				echo "<br/>";
				if ($session->check('Auth.User.id'))
				{
					if ($session->read('Auth.User.id') == $comment['User']['id'])
					{
						echo $html->link(__('Delete'),array('plugin'=>'events','controller'=>'events','action'=>'delete_comment',$comment['EventComment']['id']));
					}
				}
				echo "</div><div class='clear'></div></div><div class='clear'></div>";					
			}
			echo "<br/>";
		
		}
				else
				{
					echo __("No one has commented on this event yet.");
				}
				?><?php
		if(!empty($loggedInUser)) 
		{	
			echo " <label>".__("Enter Your Reply")."</label>";
			echo $form->create(array('type'=>'POST','action'=>'add_comment'));
			echo $form->textarea('comment');
			echo $form->hidden('eventId',array('value'=>$event['Event']['id']));
			echo $form->end(__('Add Comment'),array('div'=>array('class'=>'alignRight')));
		}
		?>
	</div>
	
	<!--
	<div class="related">
		<h4><?php echo __('Attendees');?></h4>
		<?php
		foreach($attendingUsers as $user)
		{
			echo $html->link($user["User"]['display_name'],array('plugin'=>'users','controller'=>'users','action'=>'profile',$user["User"]['slug']));
		}
		?>
	</div>
	<div class="related">
		<h4><?php echo __('Considered Cool By');?></h4>
		<?php
		foreach($interestedUsers as $user)
		{
			echo $html->link($user["User"]['display_name'],array('plugin'=>'users','controller'=>'users','action'=>'profile',$user["User"]['slug']));
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		?>
	</div>
	-->
	

</div>
<div class="clear"></div>		

<script>
function doIt(){
	var eventId = <?php echo $event['Event']['id'];?>;
	var comment = document.getElementById('EventCommentEventComments').value;
	var url = "<?php echo $html->url(array('action'=>'add_comment'))?>";		
	url += '/eventId:'+eventId+'/comment:'+comment;
	return url;
}
</script>